'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');

var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);

var _defineProperty2 = require('babel-runtime/helpers/defineProperty');

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

var _extends3 = require('babel-runtime/helpers/extends');

var _extends4 = _interopRequireDefault(_extends3);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _collapse = require('antd/lib/collapse');

var _collapse2 = _interopRequireDefault(_collapse);

var _BgColorsOutlined = require('@ant-design/icons/BgColorsOutlined');

var _BgColorsOutlined2 = _interopRequireDefault(_BgColorsOutlined);

var _Icon = require('./common/Icon');

var _Icon2 = _interopRequireDefault(_Icon);

var _Color = require('./common/Color');

var _Color2 = _interopRequireDefault(_Color);

var _BackGroundImage = require('./common/BackGroundImage');

var _BackGroundImage2 = _interopRequireDefault(_BackGroundImage);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var Panel = _collapse2['default'].Panel;

var EditorBg = function (_Component) {
    (0, _inherits3['default'])(EditorBg, _Component);

    function EditorBg(props) {
        (0, _classCallCheck3['default'])(this, EditorBg);

        var _this = (0, _possibleConstructorReturn3['default'])(this, (EditorBg.__proto__ || Object.getPrototypeOf(EditorBg)).call(this, props));

        _this.onChange = function (key, v, isDrag) {
            var value = (0, _extends4['default'])({}, _this.props.value, (0, _defineProperty3['default'])({}, key, v));
            _this.props.onChange('background', value, isDrag);
        };

        _this.imageRef = _react2['default'].createRef();
        return _this;
    }

    (0, _createClass3['default'])(EditorBg, [{
        key: 'render',
        value: function render() {
            var _this2 = this;

            var _props = this.props,
                value = _props.value,
                locale = _props.locale,
                onChange = _props.onChange,
                editorElem = _props.editorElem,
                props = (0, _objectWithoutProperties3['default'])(_props, ['value', 'locale', 'onChange', 'editorElem']);

            return _react2['default'].createElement(
                Panel,
                (0, _extends4['default'])({}, props, { header: props.header || locale.header, forceRender: true }),
                _react2['default'].createElement(_Color2['default'], {
                    onChange: function onChange(e, isDrag) {
                        _this2.onChange('color', e, isDrag);
                    },
                    title: _react2['default'].createElement(
                        _Icon2['default'],
                        { adapter: true, prompt: locale.color },
                        _react2['default'].createElement(_BgColorsOutlined2['default'], null)
                    ),
                    color: value.color
                }),
                _react2['default'].createElement(_BackGroundImage2['default'], {
                    ref: this.imageRef,
                    onChange: function onChange(e, isDrag) {
                        _this2.onChange('image', e, isDrag);
                    },
                    locale: locale,
                    value: value.image,
                    editorElem: editorElem,
                    imageSelect: props.imageSelect,
                    onImageSelectClick: props.onImageSelectClick
                })
            );
        }
    }]);
    return EditorBg;
}(_react.Component);

EditorBg.propTypes = {
    className: _propTypes2['default'].string,
    header: _propTypes2['default'].string,
    onChange: _propTypes2['default'].func,
    value: _propTypes2['default'].object,
    locale: _propTypes2['default'].object,
    editorElem: _propTypes2['default'].any,
    imageSelect: _propTypes2['default'].bool,
    onImageSelectClick: _propTypes2['default'].func
};
EditorBg.defaultProps = {
    className: 'editor-bg',
    value: {
        color: null,
        image: {
            url: [''],
            repeat: ['repeat'],
            position: ['center'],
            size: ['contain'],
            attachment: ['scroll']
        }
    },
    onChange: function onChange() {},
    onImageSelectClick: function onImageSelectClick(img) {},
    imageSelect: false
};


EditorBg.componentName = 'EditorBackGround';

exports['default'] = EditorBg;
module.exports = exports['default'];